function dispUserView() {

	$("#b1txt").text("Create Complaint");
	$("#b2txt").text("View Complaints");
	$("#b3txt").text("View Notification");
	
	$("#SideBarButton4").hide();

	$("#SideBarButton1").off().click(function() {
		dispCreateComplaint();
	});
	$("#SideBarButton2").off().click(function() {
		dispUserComplaints();
	});
	$("#SideBarButton3").off().click(function() {
		dispNotification();
	});
	$("#SideBarButton4").off().click(function() {

	});

	$("#dispCont .grid").hide();

	dispCreateComplaint();

}

function dispCreateComplaint() {

	$("#dispCont .grid").hide();

	$("#SideBarButton1").removeClass("info").addClass("warning");
	$("#SideBarButton2").removeClass("warning").addClass("info");
	$("#SideBarButton3").removeClass("warning").addClass("info");
	$("#SideBarButton4").removeClass("warning").addClass("info");

	$("#createcomp").off().submit(function() {
		createComplaint();
		return false;
	});

	var options = $("#departmentselect");
	options.empty();
	$.getJSON("/ComplaintReg/rest/service/getDepartments", function(data) {
		$.each(data, function() {
			options.append($("<option />").val(this.did).text(this.dept_name));
		});
	});
	$("#DivUserCreateComplaint").slideDown();
}

function createComplaint() {

	$.ajax({
		type : "POST",
		url : "/ComplaintReg/rest/service/createComplaint",
		data : $("#createcomp").serialize(),
		success : function(data) {
			//console.log(data);
			if (data == "true") {
				$.Notify({
					content : "Complaint created successfully",
					style : {
						background : 'DeepSkyBlue'
					}
				});
			} else {
				$.Notify({
					content : datas,
					style : {
						background : 'coral'
					}
				});
			}
		}
	});
}

function dispUserComplaints() {

	$("#dispCont .grid").hide();

	$("#SideBarButton1").removeClass("warning").addClass("info");
	$("#SideBarButton2").removeClass("info").addClass("warning");
	$("#SideBarButton3").removeClass("warning").addClass("info");
	$("#SideBarButton4").removeClass("warning").addClass("info");

	$("#complaintsTable tbody").empty();

	$.ajax({
		type : "POST",
		url : "/ComplaintReg/rest/service/getComplaints",
		success : function(data) {
			// console.log(data);
			$.each(data, function(key, val) {
				var row = "<tr><td>" + val.cid + "</td><td>" + val.location + "</td><td>" + val.date_submission + "</td><td>"
						+ val.description + "</td><td><button class=" + "userEdit" + ">Edit</button></tr>";
				$("#complaintsTable tbody").append(row);
			});

			var $rows = $('#complaintsTable tr').not('thead tr');
			$('#InputCompTableSearch').keyup(function() {
				var val = $.trim($(this).val()).replace(/ +/g, ' ').toLowerCase();

				$rows.show().filter(function() {
					var text = $(this).text().replace(/\s+/g, ' ').toLowerCase();
					return !~text.indexOf(val);
				}).hide();
			});

			$(".userEdit").click(function() {
				var row = $(this).parents('tr').get(0);
				console.log($(row.cells[0]).text().trim());

				var status = editComplaint($(row.cells[0]).text().trim());

				/*		if (status = "true") {
							console.log(this);
							$(this).removeClass("warning").addClass("success");
							$(this).off();
							$(this).text("Resolved");
						} else if (status == "false") {
							$(this).addClass("warning");
						}*/
			});

		}
	});

	$("#ComplaintList").slideDown();

	return false;
}

function editComplaint(cid) {

	$("#dispCont .grid").hide();

	var options = $("#departmentselect");
	options.empty();
	$.getJSON("/ComplaintReg/rest/service/getDepartments", function(data) {
		$.each(data, function() {
			options.append($("<option />").val(this.did).text(this.dept_name));
		});
	});

	$.ajax({
		type : "POST",
		url : "/ComplaintReg/rest/service/getComplaintById",
		data : {
			'cid' : cid
		},
		success : function(data) {
			console.log(data);
			$("#departmentselect").val(data.did);
			$("#inputLocation").val(data.location);
			$("#textareaDescription").val(data.description);
		}
	});

	$("#createcomp").off().submit(function() {

		var postData = $('#createcomp').serialize();
		postData += "&cid=" + encodeURIComponent(cid);
		console.log(postData);
		
		$.ajax({
			type : "POST",
			url : "/ComplaintReg/rest/service/updateComplaint",
			data : postData,
			success : function(data) {
				console.log(data);
				if (data == "true") {
					$.Notify({
						content : "Complaint updated successfully",
						style : {
							background : 'green'
						}
					});
					
					dispUserComplaints();
					
				} else {
					$.Notify({
						content : "Unable to update complaint",
						style : {
							background : 'coral'
						}
					});
				}
			}
		});
		
		return false;

	});

	$("#DivUserCreateComplaint").slideDown();

}

//manish..............................
function dispNotification() {
	
	$("#dispCont .grid").hide();
	
	$("#SideBarButton1").removeClass("warning").addClass("info");
	$("#SideBarButton2").removeClass("warning").addClass("info");
	$("#SideBarButton3").removeClass("info").addClass("warning");
	$("#SideBarButton4").removeClass("warning").addClass("info");

	$("#complaintsTable tbody").empty();
	
	$.ajax({
		type : "POST",
		url : "/ComplaintReg/rest/service/getNotification",
		success : function(data) {
			// console.log(data);
			$.each(data, function(key, val) {
				var row = "<tr><td>" + val.cid + "</td><td>" + val.location + "</td><td>" + val.date_submission + "</td><td>"
						+ val.description + "</td><td></tr>";
				$("#complaintsTable tbody").append(row);
			});
			
			var $rows = $('#complaintsTable tr').not('thead tr');
			$('#InputCompTableSearch').keyup(function() {
			    var val = $.trim($(this).val()).replace(/ +/g, ' ').toLowerCase();
			    
			    $rows.show().filter(function() {
			        var text = $(this).text().replace(/\s+/g, ' ').toLowerCase();
			        return !~text.indexOf(val);
			    }).hide();
			});

		}
	});

	$("#ComplaintList").slideDown();

	return false;
}
//....................................